<template>
	<div>
		<el-dialog :title="dialog.title" :visible.sync="dialogVisibleJiLiang" width="1025px" :before-close="hide">
			<div style="position:relative;">
				<div class="search">
					<input type="text" class="input" v-model="keywords" :placeholder="dialog.placeholder">
					<el-button type="primary" size="medium" @click="getList">搜索</el-button>
				</div>
				<el-tabs type="border-card">
					<el-tab-pane label="搜索结果">
						<el-button size="mini" @click="opaFun(true)">全选</el-button>
						<el-row :gutter="5" class="drugArr">
							<el-col :span="8" v-for="(item,index) in lists"><div class="drug" :class="{'active':item.checked}" @click="checkFun(item)" :title="item.name">{{item.name}}</div></el-col>
						</el-row>
					</el-tab-pane>
					<el-tab-pane label="选中结果">
						<el-button size="mini" @click="opaFun(false)">全部取消</el-button>
						<el-row :gutter="5" class="drugArr">
							<el-col :span="8" v-for="(item,index) in lists" v-if="item.checked"><div class="drug" @click="checkFun(item)" :title="item.name">{{item.name}}</div></el-col>
						</el-row>
					</el-tab-pane>
				</el-tabs>
			</div>
			<span slot="footer" class="dialog-footer">
				<el-button type="primary" @click="sureFun">确 认</el-button>
				<el-button @click="dialogVisibleJiLiang = false">关 闭</el-button>
			</span>
		</el-dialog>
	</div>
</template>

<script>
	export default {
		data () {
			return {
				openType:"",
			}
		},
		props:{
			checkId:{
				type:String
			},
			ctype:{
				type:String,
				default:"剂量"
			},
			dataObj:{
				type:Object
			},
			cintype:{
				type:String
			}
		},
		data () {
			return {
				dialogVisibleJiLiang:false,
				dialog:{
					title:"",
					placeholder:""
				},
				type:"jl",
				keywords:"",
				lists:[]
			}
		},
		mounted(){
			if(this.ctype == '剂量'){
				this.type='jl';
				this.dialog={
					title:"给药途径选择-复选",
					placeholder:"请输入给药途径"
				};
			}else if(this.ctype == '相互作用'){
				this.type='xhzy';
				this.dialog={
					title:"药品选择-复选",
					placeholder:"请输入药品"
				};
			}else if(this.ctype == '体外配伍'){
				this.type='twpw';
				this.dialog={
					title:"药品选择-复选",
					placeholder:"请输入药品"
				};
			}else if(this.ctype == '超适应症'){
				this.type='csyz';
				this.dialog={
					title:"诊断选择-复选",
					placeholder:"请输入诊断"
				};
			}else if(this.ctype == '给药途径'){
				this.type='gytj';
				this.dialog={
					title:"给药途径选择-复选",
					placeholder:"请输入给药途径"
				};
			}else if(this.ctype == '重复用药'){
				this.type='cfyy';
				this.dialog={
					title:"药品选择-复选",
					placeholder:"请输入药品"
				};
			}else if(this.ctype == '药物禁忌症'){
				this.type='ywjjz';
				this.dialog={
					title:"诊断选择-复选",
					placeholder:"请输入诊断名称"
				};
			}else if(this.ctype == '不良反应'){
				this.type='blfy';
				this.dialog={
					title:"诊断选择-复选",
					placeholder:"请输入诊断名称"
				};
			}else if(this.ctype == '配伍浓度'){
				if(this.cintype == "给药途径"){
					this.type='pwnd_gytj';
					this.dialog={
						title:"给药途径-复选",
						placeholder:"请选择给药途径"
					};
				}else if(this.cintype == "溶媒药品"){
					this.type='pwnd_rmyp';
					this.dialog={
						title:"溶媒药品-复选",
						placeholder:"请选溶媒药品"
					};
				}		
			}else if(this.ctype == "抗菌药物三联重复用药"){
				this.type='kjywsl';
				this.dialog={
					title:"药品-复选",
					placeholder:"请选药品"
				};
			}else if(this.ctype == "围术期用药"){
				this.type='wsqyy';
				this.dialog={
					title:"手术选择-复选",
					placeholder:"请选择手术"
				};
			}else if(this.ctype == '肝损害剂量'){
				if(this.cintype == "给药途径"){
					this.type='gshjl_gytj';
					this.dialog={
						title:"给药途径-复选",
						placeholder:"请选择给药途径"
					};
				}else if(this.cintype == "疾病状态"){
					this.type='gshjl_jbzt';
					this.dialog={
						title:"疾病状态-复选",
						placeholder:"请选疾病状态"
					};
				}		
			}else if(this.ctype == '肾损害剂量'){
				if(this.cintype == "给药途径"){
					this.type='sshjl_gytj';
					this.dialog={
						title:"给药途径-复选",
						placeholder:"请选择给药途径"
					};
				}else if(this.cintype == "疾病状态"){
					this.type='sshjl_jbzt';
					this.dialog={
						title:"疾病状态-复选",
						placeholder:"请选疾病状态"
					};
				}else if(this.cintype  == "检验值指标"){
					this.type='sshjl_jyzzb';
					this.dialog={
						title:"检验值指标-复选",
						placeholder:"请选检验值指标"
					};
				}		
			}
		},
		methods:{
			async getList(){
				let res;
				if(this.type=='jl'){
					res=await this.$custom.listRoute({
						keywords:this.keywords
					})
				}else if(this.type == 'xhzy'){
					res=await this.$custom.listInter({
						drugUniqueCode:this.dataObj.drugUniqueCode,
						keywords:this.keywords
					})
				}else if(this.type == 'twpw'){
					res=await this.$custom.listIv({
						drugUniqueCode:this.dataObj.drugUniqueCode,
						keywords:this.keywords
					})
				}else if(this.type == 'csyz'){
					res=await this.$custom.listIndica({
						drugUniqueCode:this.dataObj.drugUniqueCode,
						keywords:this.keywords
					})
				}else if(this.type == 'gytj'){
					res=await this.$custom.listDrugrouteDrugroute({
						drugUniqueCode:this.dataObj.drugUniqueCode,
						keywords:this.keywords
					})
				}else if(this.type == 'pwnd_gytj'){//配伍浓度-给药途径
					res=await this.$custom.listRoute({
						drugUniqueCode:this.dataObj.drugUniqueCode,
						keywords:this.keywords
					})
				}else if(this.type == 'pwnd_rmyp'){//配伍浓度-溶媒药品
					res=await this.$custom.listDrugMatch({
						drugUniqueCode:this.dataObj.drugUniqueCode,
						keywords:this.keywords
					})
				}else if(this.type == "wsqyy"){
					res=await this.$custom.listPreOperation({
						drugUniqueCode:this.dataObj.drugUniqueCode,
						keywords:this.keywords
					})
				}else if(this.type == "cfyy"){
					res=await this.$custom.listDuptherapyDrugroute({
						drugUniqueCode:this.dataObj.drugUniqueCode,
						keywords:this.keywords
					})
				}else if(this.type == "ywjjz"||this.type == "blfy"){
					res=await this.$custom.listModuleDrugroute({
						drugUniqueCode:this.dataObj.drugUniqueCode,
						keywords:this.keywords,
						moduleId:"7"
					})
				}else if(this.type == "kjywsl"){
					res=await this.$custom.listDrugMatch({
						drugUniqueCode:this.dataObj.drugUniqueCode,
						keywords:this.keywords
					})
				}else if(this.type == "gshjl_gytj" || this.type == "sshjl_gytj"){//肝肾损害剂量-给药途径
					res=await this.$custom.listDrugrouteDrugroute({
						// drugUniqueCode:this.dataObj.drugUniqueCode,
						keywords:this.keywords
					})
				}else if(this.type == "gshjl_jbzt" || this.type == "sshjl_jbzt"){//肝肾损害剂量-疾病状态
					res=await this.$custom.liverDamageList({
						// drugUniqueCode:this.dataObj.drugUniqueCode,
						keywords:this.keywords
					})
				}else if(this.type == "sshjl_jyzzb"){//肾损害剂量-检验值
					res=await this.$custom.listRenalDamage({
						// drugUniqueCode:this.dataObj.drugUniqueCode,
						keywords:this.keywords
					})
				}
				
				
				
				
				var checkId=this.checkId.split(",");
				for(var i=0;i<res.length;i++){
					res[i].checked=false;
				}
				for(var j=0;j<checkId.length;j++){
					for(var i=0;i<res.length;i++){
						if(checkId[j] == res[i].code){
							res[i].checked=true;
							break;
						}
					}
				}
				this.lists=res;
			},
			hide () {
				this.dialogVisibleJiLiang = false;
			},
			show(){
				this.dialogVisibleJiLiang = true;
				// this.keywords="";
				this.getList();
			},
			checkFun(item){
				item.checked=!item.checked
			},
			opaFun(type){
				for(var i=0;i<this.lists.length;i++){
					this.lists[i].checked=type;
				}
			},
			sureFun(){
				var selectId=[],selectName=[];
				for(var i=0;i<this.lists.length;i++){
					if(this.lists[i].checked){
						selectId.push(this.lists[i].code)
						selectName.push(this.lists[i].name)
					}
				}
				this.hide();
				this.$emit("selectFun",selectId.join(","),selectName.join(","));
			}	
		}
	}
</script>

<style scoped lang="scss">
	.search{
		width:50%;
		height:40px;
		position:absolute;
		right:20px;
		top:2px;
		z-index:999;
		text-align:right;
		.input{
			width:200px;
			height:28px;
			line-height:28px;
			margin-right:10px;
			border-radius: 4px;
			border: 1px solid #dcdfe6;
			padding:0 15px;
			color:#606266;
		}
	}
	.drugArr{
		padding:15px;
		box-sizing: border-box;
		.drug{
			width:100%;
			height:22px;
			line-height:22px;
			margin-bottom:5px;
			padding-left:5px;
			cursor: pointer;
			overflow: hidden;
			text-overflow:ellipsis;
			white-space: nowrap;
		}
		.drug.active{
			color:#fff;
			background:#409eff;
		}
	}
</style>
